$(function() {
	$('.doubledate').kuiDate({
		className : 'doubledate',
		isDisabled : "0"
	});
});

function selectQuestion() {
	//["id","name","createFileTime","effectDate","uneffectDate","status"]
	$("#questionnaireId").blur();
	initSelecter({
		url : '../questionnaire/list',
		heads : ["id", "name"],
		titles : ["Id", "名称"],
		zindex : 500, // 缺省值
		callBack : questionSelected
	});

}

function questionSelected(response, row) {
	var id = response.getValue("id", row);
	var name = response.getValue("name", row);
	$("#questionnaireId").empty();
	$("#questionnaireId").append($("<option selected='selected' value='" + id + "'>" + name + "</option>"));
}

/**
 * 查询
 */
function search() {

	var shopId = $("#shopName").val();
	var questionnaireId = $("#questionnaireId").val();

	var createFileTime1 = $("#createFileTime1").val();
	var createFileTime2 = $("#createFileTime2").val();

	if (qmsk.isEmpty(questionnaireId)) {
		artAlert('请选择主题！');
		return;
	}
	_pagination = new Pagination({
		url : '../questionnaire/return/list/' + questionnaireId,
		data : {
			shopId : shopId,
			createFileTime1 : createFileTime1,
			createFileTime2 : createFileTime2
		},
		success : printListToPage,
		pagerHandler : 'pager'
	});
}

/**
 * 查询
 */
function down() {

	var shopId = $("#shopName").val();
	var questionnaireId = $("#questionnaireId").val();

	var createFileTime1 = $("#createFileTime1").val();
	var createFileTime2 = $("#createFileTime2").val();

	if (qmsk.isEmpty(questionnaireId)) {
		artAlert('请选择主题！');
		return;
	}

	qmsk.redirectUrl('../questionnaire/return/down/' + questionnaireId, {
		shopId : shopId,
		createFileTime1 : createFileTime1,
		createFileTime2 : createFileTime2
	});

}

/**
 * 显示
 */
function printListToPage(rst) {
	var response = new qmsk.Response(rst);

	var heads = response.heads;
	var datas = response.data;
	var len = response.length;
	var col = response.col;
	var row = response.row;

	var $tbody = $("#returnList");
	$tbody.empty();

	var $thead = $("#returnHeads");
	$thead.empty();

	$thead.append("<th>主题</th>");
	$thead.append("<th>用户名称</th>");
	$thead.append("<th>手机</th>");
	$thead.append("<th>时间</th>");

	var dataTableHeads = ["questionnaireName", "customerName", "mp", "createFileTime"];
	for (var i = 6; i < col; i++) {
		$thead.append("<th>" + heads[i] + "</th>");
		dataTableHeads.push(heads[i]);
	}

	qmsk.dataTable({
		tbodyId : 'returnList',
		heads : dataTableHeads,
		response : response,
		sup : ['sup', '共 [index] 条'],
		handler : []
	});

}

function updateAndDelButton(serviceId, row) {
	return "<input class='del' type='button' value='删除' onClick='del(" + serviceId + ")'/>" + "<input type='button' class='common_btn' value='修改' onClick='toUpdate(" + serviceId + ")'/>";
}
